package me.leiusual.sharing.api

import com.google.gson.JsonObject
import io.reactivex.Single
import me.leiusual.sharing.api.model.*
import okhttp3.MultipartBody
import retrofit2.http.Body
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST

/**
 * Create by leiusual on 2018/7/18
 */
interface ApiOauth2 {

  companion object {
    const val BASE_URL = "https://www.lingling9.com:8444"

    const val GRANT_TYPE = "password"
    const val CLIENT_ID = "lingling9.app"
    const val CLIENT_SECRET = "tmt.lingling9.app"
  }

  @FormUrlEncoded
  @POST("/s/oauth/token")
  fun accessToken(
      @Field("username") username: String,
      @Field("password") password: String,
      @Field("grant_type") grantType: String = GRANT_TYPE,
      @Field("client_id") clientId: String = CLIENT_ID,
      @Field("client_secret") clientSecret: String = CLIENT_SECRET
  ): Single<AccessToken.Response>

  @FormUrlEncoded
  @POST("/s/me")
  fun userInfo(@Field("client_id") clientId: String = CLIENT_ID): Single<UserInfo.Response>

  @POST("/s/api/reg/code")
  fun sendSMS(@Body params: SendSMS.Request): Single<Unit>

  @POST("/s/api/reg/new")
  fun register(@Body params: Register.Request): Single<Register.Response>

  @POST("/s/api/user/password/update")
  fun passwordUpdate(@Body params: PasswordUpdate.Request): Single<Unit>

  @POST("/s/api/reg/password/reset")
  fun passwordReset(@Body params: PasswordReset.Request): Single<Unit>

  @POST("/s/api/user/realname")
  fun realName(@Body params: MultipartBody): Single<Unit>

  @POST("/s/api/user/realname/query")
  fun realNameQuery(@Body params: RealNameQuery.Request): Single<RealNameQuery.Response>

  @POST("/s/api/user/mobile/update")
  fun mobileUpdate(@Body params: MobileUpdate.Request): Single<Unit>

  @POST("/s/api/reg/new/qr")
  fun registerByQRCode(@Body params: RegisterByQRCode.Request): Single<RegisterByQRCode.Response>

  @POST("/s/api/user/avatar/update")
  fun avatarUpdate(@Body params: MultipartBody): Single<JsonObject>

  @POST("/s/api/user/nickname/update")
  fun nicknameUpdate(@Body params: NicknameUpdate.Request): Single<Unit>
}